//查询当前电脑ip所在地址的天气信息
function funs(){
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status == 200) {
        let res= JSON.parse(xhr.responseText)
        // console.log(data.data.city)
        let xhrs = new XMLHttpRequest();
        xhrs.onreadystatechange = function () {
            if (xhrs.status == 200 && xhrs.readyState == 4) {
                const data = JSON.parse(xhrs.responseText)
                for (let i = 0; i < data.location.length; i++) {
                    if (data.location[i].name + "市" == res.data.city) {
                        let datas = data.location[i].id;
                        if (datas) {
                            let xhr = new XMLHttpRequest();
                            xhr.onreadystatechange = function () {
                                if (xhr.status == 200 && xhr
                                    .readyState == 4) {
                                    const data = JSON.parse(xhr
                                        .responseText)
                                    let weather = document
                                        .getElementsByClassName(
                                            "weather")[0]
                                    weather.innerHTML = `
                                                    <div class="city">${res.data.city}</div>
                                                    <div class="qiwen">${data.now.temp}°C</div>
                                                    <div class="tianqi"><i class="qi-${data.now.icon}" id="icon_font"></i><span>${data.now.text }</span></div>
                                                    <div class="xiangqing">
                                                        <ul>
                                                            <li>
                                                                <div>风向</div>
                                                                <div>${data.now.windDir}</div>
                                                            </li>
                                                            <li>
                                                                <div>风力等级</div>
                                                                <div>${data.now.windScale}级</div>
                                                            </li>
                                                            <li>
                                                                <div>风速</div>
                                                                <div>${data.now.windSpeed}</div>
                                                            </li>
                                                            <li>
                                                                <div>近一小时降水量</div>
                                                                <div>${data.now.precip}mm</div>
                                                            </li>
                                                            <li>
                                                                <div>大气压强</div>
                                                                <div>${data.now.pressure}hPa</div>
                                                            </li>
                                                            <li>
                                                                <div>能见度</div>
                                                                <div>${data.now.vis}km</div>
                                                            </li>
                                                        </ul>
                                                    </div>`
                                }
                            }
                            xhr.open("GET",
                                "https://devapi.qweather.com/v7/weather/now?location=" +
                                datas +
                                "&key=2937c1738af34a358476cc6c8bce5b92",
                                true)
                            xhr.send();
                        }
                    }
                }
            }
        }
        xhrs.open("GET", "https://geoapi.qweather.com/v2/city/lookup?location=" + res.data.city + "&key=894a0feaa60b422c93f73528c1f3054f", true)
        xhrs.send();
    }
}
xhr.open("GET", `https://www.mxnzp.com/api/ip/self?app_id=kfgjykljnonufnjo&app_secret=RnB0aTd5SEpzbTg0RWZQQVVnZlNIUT09`, false)
xhr.send()
}

funs()

// AMap.plugin('AMap.CitySearch', function () {
//     var citySearch = new AMap.CitySearch()
//     citySearch.getLocalCity(function (status, result) {
//         if (status === 'complete' && result.info === 'OK') {
//             // 查询成功，result即为当前所在城市信息
//             let xhr = new XMLHttpRequest();
//             xhr.onreadystatechange = function () {
//                 if (xhr.status == 200 && xhr.readyState == 4) {
//                     const data = JSON.parse(xhr.responseText)
//                     for (let i = 0; i < data.location.length; i++) {
//                         if (data.location[i].name + "市" == result.city) {
//                             let datas = data.location[i].id;
//                             if (datas) {
//                                 let xhr = new XMLHttpRequest();
//                                 xhr.onreadystatechange = function () {
//                                     if (xhr.status == 200 && xhr
//                                         .readyState == 4) {
//                                         const data = JSON.parse(xhr
//                                             .responseText)
//                                         let weather = document
//                                             .getElementsByClassName(
//                                                 "weather")[0]
//                                         weather.innerHTML = `
//                                         <div class="city">${result.city}</div>
//                                         <div class="qiwen">${data.now.temp}°C</div>
//                                         <div class="tianqi"><i class="qi-${data.now.icon}" id="icon_font"></i><span>${data.now.text }</span></div>
//                                         <div class="xiangqing">
//                                             <ul>
//                                                 <li>
//                                                     <div>风向</div>
//                                                     <div>${data.now.windDir}</div>
//                                                 </li>
//                                                 <li>
//                                                     <div>风力等级</div>
//                                                     <div>${data.now.windScale}级</div>
//                                                 </li>
//                                                 <li>
//                                                     <div>风速</div>
//                                                     <div>${data.now.windSpeed}</div>
//                                                 </li>
//                                                 <li>
//                                                     <div>近一小时降水量</div>
//                                                     <div>${data.now.precip}mm</div>
//                                                 </li>
//                                                 <li>
//                                                     <div>大气压强</div>
//                                                     <div>${data.now.pressure}hPa</div>
//                                                 </li>
//                                                 <li>
//                                                     <div>能见度</div>
//                                                     <div>${data.now.vis}km</div>
//                                                 </li>
//                                             </ul>
//                                         </div>`
//                                     }
//                                 }
//                                 xhr.open("GET",
//                                     "https://devapi.qweather.com/v7/weather/now?location=" +
//                                     datas +
//                                     "&key=2937c1738af34a358476cc6c8bce5b92",
//                                     true)
//                                 xhr.send();
//                             }
//                         }
//                     }

//                 }
//             }
//             xhr.open("GET", "https://geoapi.qweather.com/v2/city/lookup?location=" + result
//                 .city +
//                 "&key=894a0feaa60b422c93f73528c1f3054f", true)
//             xhr.send();
//         }
//     })
// })